<?php

class LoginController extends Controller{
	
	private $_model;
	
	public function __init(){
		
		$this->_model=K('admin');
	}
	
	
	
	public function index(){
		
		if(isset($_SESSION['aid']) && isset($_SESSION['aname'])){
			go(U('Index/index'));
		}
		
		if(IS_POST){
			
			
			if(!$data=$this->_model->validate_login()) $this->error($this->_model->error);
			
			$_SESSION['aname']=$data['aname'];
			$_SESSION['aid']=$data['aid'];
			
			$this->success('登录成功',U('Index/index'));
		}
		
		$this->display();
		
	}
	
	public function code(){
		
		$code=new Code();
		$code->show();
		
	}
	
	public function out(){
		
		session(Null);
		
		$this->success('退出成功',U('Index/index'));
	}
	
}
